package cn.ad.service;

import cn.ad.common.DataUtils;
import cn.ad.handler.SqlSessionHandler;
import cn.ad.enumration.Interaction;
import cn.ad.enumration.InteractionType;
import cn.ad.enumration.Media;
import cn.ad.model.*;
import cn.ad.entity.AdTemplateSpec;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.net.URLEncoder;
import java.util.*;

/**
 * 素材
 *
 * @author yujuan.zhang
 * @from 2016-09-18
 * @since DSP V2
 */
@Service
public class AdMaterialService {

    private static Logger logger = LoggerFactory.getLogger(AdMaterialService.class);

    @Autowired
    private SqlSessionHandler sqlSessionHandler;

    @Autowired
    private CampaignService campaignService;

    public Integer selectAdMaterialIdByCreativeIdAndSizeId(Integer creativeId, Integer sizeId) {
        Map<String, Object> mapParams = new HashMap<>();
        mapParams.put("creativeId", creativeId);
        mapParams.put("sizeId", sizeId);
        return sqlSessionHandler.selectOne("adMaterialMapper.selectMaterialIdByCreativeIdAndSizeId", mapParams);
    }

    /**
     * 查询创意详细信息
     */
    private CreativeDetailModel selectCreativeById(Integer cid, Integer id) {
        Map<String, Object> creativeParams = new HashMap<>();
        creativeParams.put("campaignId", cid);
        creativeParams.put("id", id);

        // 查询创意或者素材的交互信息
        return sqlSessionHandler.selectOne("creativeMapper.creative:selectById", creativeParams);
    }

    private List<GdtMaterialModel> findGdtMaterialModels(Integer creativeId, List<Integer> materialIds){
        Map<String, Object> mapParams = new HashMap<>();
        mapParams.put("creativeId", creativeId);
        mapParams.put("materialIds", materialIds);
        return sqlSessionHandler.selectList("creativeMapper.selectOne:gdt:adx:edit",mapParams);
    }

}
